﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace ModelTest
{
    class XmlOperate
    {

        public static void TestOne()
        {
            string xml = @"<xml>
 <ToUserName><![CDATA[toUser]]></ToUserName>
 <FromUserName><![CDATA[fromUser]]></FromUserName> 
 <CreateTime>1348831860</CreateTime>
 <MsgType><![CDATA[text]]></MsgType>
 <Content><![CDATA[this is a test]]></Content>
 <MsgId>1234567890123456</MsgId>
 </xml>";
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            XmlNodeList nodeList = doc.SelectSingleNode("xml").ChildNodes;
            foreach (XmlNode item in nodeList)
            {
                Console.WriteLine(item.Name + "--->" + item.InnerText);
            }
        }

        public static void TestTwo()
        {
            XmlDocument doc = new XmlDocument();

            XmlElement xml = doc.CreateElement("xml");
            xml.AppendChild(doc.CreateElement("name"));
            XmlNode node = doc.CreateNode(XmlNodeType.CDATA, "age", null);
            node.Value = "13岁";
            xml.AppendChild(node);

            StringBuilder builder = new StringBuilder();
            XmlWriter xw = XmlWriter.Create(builder);
            xml.WriteTo(xw);
            xw.Close();
            Console.WriteLine(builder.ToString());
           // Console.WriteLine(xml.get());
        }


    }
}
